import time

from selenium.webdriver.common.by import By

from common.Utils import ForumDriver
#注册页面测试用例
class ForumEnroll:
    url = ""
    driver = ""
    def __init__(self):
        self.url = "http://127.0.0.1:9580/sign-in.html"
        self.driver = ForumDriver.driver
        self.driver.get(self.url)
    #注册成功
    def EnrollTestSuc(self):
        #输入正确的用户名、昵称、密码、确认密码、勾选条款
        self.driver.find_element(By.CSS_SELECTOR,"body > div > div > div > div:nth-child(1) > div > div.text-center.text-muted.mt-3 > a").click()
        self.driver.get("http://127.0.0.1:9580/sign-up.html")
        self.driver.find_element(By.CSS_SELECTOR,"#username").send_keys("chenyiqiyiqi")
        self.driver.find_element(By.CSS_SELECTOR,"#nickname").send_keys("chenyiqiyiqi")
        self.driver.find_element(By.CSS_SELECTOR,"#password").send_keys("456789")
        self.driver.find_element(By.CSS_SELECTOR,"#passwordRepeat").send_keys("456789")
        self.driver.find_element(By.CSS_SELECTOR,"#policy").click()
        #截图验证是否注册成功
        ForumDriver.getScreeShot()

    def EnrollTestFail(self):
        self.driver.find_element(By.CSS_SELECTOR,"body > div > div > div > div:nth-child(1) > div > div.text-center.text-muted.mt-3 > a").click()
        self.driver.get("http://127.0.0.1:9580/sign-up.html")
        # 用户名已经存在
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("chenyiqi")
        self.driver.find_element(By.CSS_SELECTOR, "#nickname").send_keys("chenyiqi")
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("123")
        self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").send_keys("123")
        self.driver.find_element(By.CSS_SELECTOR, "#policy").click()
        self.driver.find_element(By.CSS_SELECTOR,"#submit").click()
        # 验证是否注册成功
        alert=self.driver.find_element(By.CSS_SELECTOR,"body > div.jq-toast-wrap.bottom-right > div")
        print(alert.text)

        #密码和确认密码不一致
        self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#nickname").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("ccc")
        self.driver.find_element(By.CSS_SELECTOR, "#nickname").send_keys("ccc")
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("123")
        self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").send_keys("123456")
        self.driver.find_element(By.CSS_SELECTOR, "#policy").click()
        # 验证是否注册成功
        alert = self.driver.find_element(By.CSS_SELECTOR, "#signUpForm > div > div:nth-child(5) > div > div")
        print(alert.text)

        #未勾选同意条款
        self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#nickname").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("ccc")
        self.driver.find_element(By.CSS_SELECTOR, "#nickname").send_keys("ccc")
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("123")
        self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").send_keys("123")
        # 截图验证是否注册成功
        ForumDriver.getScreeShot()

        #用户信息未填写完整
        self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#nickname").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("ccc")
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("123")
        self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").send_keys("123")
        self.driver.find_element(By.CSS_SELECTOR, "#policy").click()
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        # 截图验证是否注册成功
        alert = self.driver.find_element(By.CSS_SELECTOR, "#signUpForm > div > div:nth-child(3) > div")
        print(alert.text)

Enroll=ForumEnroll()